//
//  ActivitylistViewController.m
//  豆瓣电影app
//
//  Created by 洛洛大人 on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ActivitylistViewController.h"
#import "activitylistModel.h"
#import "activitylistTableViewCell.h"
@interface ActivitylistViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableView;
@property(nonatomic, retain)NSMutableArray *ActivityArray;
@end

@implementation ActivitylistViewController
-(void)dealloc{
    [_tableView release];
    [_ActivityArray release];
    [super dealloc];
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.ActivityArray = [NSMutableArray array];
    self.navigationItem.title = @"活动";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.41 green:0.61 blue:0.68 alpha:1];
    
    [self handleData];
    [self creatView];
}


-(void)handleData {
    
    NSString *path = [[NSBundle mainBundle]pathForResource:@"activitylist" ofType:@"txt"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    
    NSError *error = nil;
    
    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
    NSArray *array = [dictionary objectForKey:@"events"];
    
    for (NSDictionary *dic in array) {
        activitylistModel *model = [[activitylistModel alloc]init];
        
        [model setValuesForKeysWithDictionary:dic];
        [self.ActivityArray addObject:model];
               
    }
   }

-(void)creatView {
    
    self.tableView = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    self.tableView.rowHeight = 180;
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
 
    
    [self.tableView registerClass:[activitylistTableViewCell class] forCellReuseIdentifier:@"ActivityCell"];
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    activitylistTableViewCell *activityCell = [tableView dequeueReusableCellWithIdentifier:@"ActivityCell"];
    
    activitylistModel *amodel = [self.ActivityArray objectAtIndex:indexPath.row];
    activityCell.model = amodel;
    
  
    return activityCell;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
    return self.ActivityArray.count;
}








@end
